/*
 * @Description: 客户端接入管理接口
 * @Author: chendingfengmail@163.com
 * @Date: 2021-11-05 18:07:25
 * @LastEditTime: 2022-01-10 15:42:11
 * @LastEditors: chendingfengmail@163.com
 * @Reference: 
 */
import { request } from "../service";

const clientDetails = {
  //添加客户端接入信息
  add(param) {
    return request({
      url: "/auth/clientDetails/add",
      method: "post",
      data: addDefaultParam(param),
    })
  },

  //删除客户端接入信息
  del(id) {
    return request({
      url: `/auth/clientDetails/delete/${id}`,
      method: 'delete',
    })
  },

  //查找客户端接入信息列表
  findList(param) {
    return request({
      url: '/auth/clientDetails/findByAttributes',
      method: 'get',
      params: param,
    })
  },

  //通过主键查找客户端接入信息
  findById(id) {
    return request({
      url: `/auth/clientDetails/findById/${id}`,
      method: 'get',
    })
  },

  //通过属性查找客户端接入信息总数
  findMax(param) {
    return request({
      url: '/auth/clientDetails/findMaxByAttributes',
      method: 'get',
      params: param,
    })
  },

  //更新客户端接入信息
  update(param) {
    return request({
      url: '/auth/clientDetails/update',
      method: 'put',
      data: addDefaultParam(param),
    })
  },

  //更新客户端接入app密钥
  updatePwd(param) {
    return request({
      url: '/auth/clientDetails/updatePwd',
      method: 'put',
      params: param,
    })
  }

}

/**
 * 添加缺省参数值
 * @param {*} param 原始参数
 * @returns 携带缺省参数返回
 */
function addDefaultParam(param) {
  let params = param;
  params['authorizedGrantTypes'] = 'client_credentials,refresh_token';
  params['id'] = param.clientId
  params['autoapprove'] = true
  return params;
}

export default clientDetails;
